<?php
//ob_start();
//ob_clean();

$types = array ( "pixel", "sample", "gradient", "elipse" );

$type = $_REQUEST["type"];
$type = in_array($_REQUEST["type"], $types) ? $_REQUEST["type"] : reset($types);

$image_type = IMAGETYPE_PNG;
$extension = image_type_to_extension($image_type);
$mime = image_type_to_mime_type($image_type);
switch ($type) {
    case "sample":
        twoColorSemple($_REQUEST["cl"]);
        break;
}

function twoColorSemple($cl, $channel = 7)
{
    global $image_type, $extension;
    $im = @imagecreate(2, 2) or die("Cannot Initialize new GD image stream");
    $color1 = imagecolorallocatealpha($im, $channel|1?$cl:0, $channel|2?$cl:0, $channel|4?$cl:0, 0);
    $color2 = imagecolorallocatealpha($im, 0, 0, 0, 127);
    imagefill($im, 0, 0, $color1);
    /*imagerectangle($im, 0, 0, 2, 2, $color1);*/
    imageline($im, 1, 0, 1, 0, $color2);
    imageline($im, 0, 1, 0, 1, $color2);
    //imagerectangle($im, 0, 1, 0, 1, $color2);
    header("Content-type: " . image_type_to_mime_type($image_type));
    header('Content-Disposition: attachment; filename="bg-sample'.$extension.'"');
    imagepng($im);
    imagedestroy($im);
}

    //ob_end_flush();

?>